package model;

import java.util.Objects;

public class Goods {
    /**
     * 商品编号
     */
    private String goodNo;

    /**
     * 商品名称
     */
    private String goodsName;

    /**
     * 成本
     */
    private double cost;

    /**
     * 售价
     */
    private double price;

    /**
     * 数量
     */
    private int count;

    /**
     * 商品分类
     */
    private Category category;

    public Goods() {}

    public Goods(String no) {
        this.goodNo = no;
    }

    public Goods(String goodNo, String goodsName, double cost, double price, int count, Category category) {
        this.goodNo = goodNo;
        this.goodsName = goodsName;
        this.cost = cost;
        this.price = price;
        this.count = count;
        this.category = category;
    }

    // getter / setter


    public String getGoodNo() {
        return goodNo;
    }

    public void setGoodNo(String goodNo) {
        this.goodNo = goodNo;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @Override
    public String toString() {
        return "【商品】" +
                "商品编号：" + goodNo +
                ", 商品名称：" + goodsName +
                ", 进价：" + cost +
                ", 售价：" + price +
                ", 库存：" + count +
                ", 分类：" + (category == null? "无" : category.getName());
    }

    public String show(){
        return "【商品】" +
                "商品编号：" + goodNo +
                ", 商品名称：" + goodsName +
                ", 售价：" + price +
                ", 库存：" + count +
                ", 分类：" + (category == null? "无" : category.getName());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Goods goods = (Goods) o;
        return goodNo.equals(goods.goodNo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(goodNo);
    }
}

